package com.longjianghuasheng.logistics.business.main

import android.os.Bundle


import com.longjianghuasheng.logistics.R
import com.longjianghuasheng.logistics.appViewModel
import com.longjianghuasheng.logistics.base.BaseFragment
import com.longjianghuasheng.logistics.databinding.FragmentMainBinding
import com.longjianghuasheng.logistics.ext.init
import com.longjianghuasheng.logistics.ext.initMain
import com.longjianghuasheng.logistics.ext.interceptLongClick
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel

/**
 * 时间　: 2019/12/27
 * 作者　: hegaojian
 * 描述　:项目主页Fragment
 */
class MainFragment : BaseFragment<BaseViewModel, FragmentMainBinding>() {


    override fun layoutId() = R.layout.fragment_main

    override fun initView(savedInstanceState: Bundle?) {
        //初始化viewpager2
        with(mDatabind) {
            mainViewpager.initMain(this@MainFragment)
            //初始化 bottomBar


            mainBottom.init {
                when (it) {
                    R.id.menu_home -> mainViewpager.setCurrentItem(0, false)
                    R.id.menu_classify -> mainViewpager.setCurrentItem(1, false)
                    R.id.menu_new -> mainViewpager.setCurrentItem(2, false)
                    R.id.menu_shop_car -> mainViewpager.setCurrentItem(3, false)
                    R.id.menu_mine -> mainViewpager.setCurrentItem(4, false)
                }
            }
            mainBottom.interceptLongClick(
                R.id.menu_home,
                R.id.menu_classify,
                R.id.menu_new,
                R.id.menu_shop_car,
                R.id.menu_mine
            )
        }
    }

    override fun createObserver() {


        appViewModel.userInfo.observeInFragment(this) {


            if (it == null) {
                //退出登录监听
                mDatabind.mainBottom.selectedItemId = R.id.menu_home
            }
        }


    }
}